package com.benyq.networkprogramme.udp

import java.net.DatagramSocket
import java.net.InetAddress
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import android.R.attr.data
import android.util.Log
import java.net.DatagramPacket


/**
 * @author benyq
 * @date 18-9-27 14:51
 * @E-mail： 1520063035@qq.com
 * @description
 */
object UdpSender {

    private var executorService: ExecutorService = Executors.newSingleThreadExecutor()

    private val socket = DatagramSocket(8888)

    private val serverAddress = InetAddress.getByName("192.168.0.104")
    private val port = 8888

    fun send(msg: String){
        executorService.execute {
            val data = msg.toByteArray()
            val packet = DatagramPacket(data, data.size, serverAddress, port)
            socket.send(packet)
            Log.e("susan", msg)
        }
    }
}